// var i;
// var $bundleConfig = require("./BundleConfig");
// var $eventManager = require("./EventManager");
// var $resKeeper = require("./ResKeeper");
// var $uIManager = require("./UIManager");
// var $commonUtils = require("./CommonUtils");
// var $evenType = require("./EvenType");
// var $playerDataManager = require("./PlayerDataManager");
// var $uIConfig_Home = require("./UIConfig_Home");
// var g = cc._decorator;
// var _ = g.ccclass;
// var y = g.property;
// var m = g.inspector;
// var v = (function (e) {
//     function t() {
//         var t = (null !== e && e.apply(this, arguments)) || this;
//         t.icontag = null;
//         t.count = null;
//         t.addtype = 1;
//         t.clickthen = 0;
//         return t;
//     }
//     __extends(t, e);
//     t.prototype.onEnable = function () {
//         $eventManager.EventMgr.addEventListener($evenType.EVENT_TYPE.Home_Add_Gold, this.onAddGold, this);
//         $eventManager.EventMgr.addEventListener($evenType.EVENT_TYPE.Hall_ResetRich, this.updateUi, this);
//         this.updateUi();
//     };
//     t.prototype.updateUi = function () {
//         if (this.count) {
//             switch (this.addtype) {
//                 case 1:
//                     this.count.string =
//                         $playerDataManager.PlayerDataMgr.globalData.power +
//                         "/" +
//                         $playerDataManager.PlayerDataMgr.globalData.maxPower;
//                     break;
//                 case 2:
//                     this.count.string = "" + $playerDataManager.PlayerDataMgr.globalData.gold;
//                     break;
//                 case 3:
//                     this.count.string = "" + $playerDataManager.PlayerDataMgr.globalData.diamond;
//             }
//         }
//     };
//     t.prototype.onAddGold = function (e, t) {
//         if (this.addtype == e) {
//             switch (e) {
//                 case 1:
//                     $commonUtils.default.showCoin(this.icontag.convertToWorldSpaceAR(cc.v2(0, 0)), null, t, "power");
//                     break;
//                 case 2:
//                     $commonUtils.default.showCoin(this.icontag.convertToWorldSpaceAR(cc.v2(0, 0)), null, t, "jinbi");
//                     break;
//                 case 3:
//                     $commonUtils.default.showCoin(this.icontag.convertToWorldSpaceAR(cc.v2(0, 0)), null, t, "zuanshi");
//             }
//         }
//     };
//     t.prototype.onDisable = function () {
//         $eventManager.EventMgr.rmEventListener($evenType.EVENT_TYPE.Home_Add_Gold, this.onAddGold, this);
//         $eventManager.EventMgr.rmEventListener($evenType.EVENT_TYPE.Hall_ResetRich, this.updateUi, this);
//     };
//     t.prototype.showDeBug = function () {
//         if ($playerDataManager.PlayerDataMgr.WHITE_NAME_NO_VIDEO) {
//             this.clickthen += 1;
//             console.log("点击次数", this.clickthen);
//             if (this.clickthen > 5) {
//                 $uIManager.default.open($bundleConfig.BundleNames.Home, $uIConfig_Home.UIView_Home.UI_DeBug);
//             }
//             this.unschedule(this.resetClickThen);
//             this.scheduleOnce(this.resetClickThen, 0.4);
//         }
//     };
//     t.prototype.resetClickThen = function () {
//         this.clickthen = 0;
//     };
//     __decorate([y(cc.Node)], t.prototype, "icontag", void 0);
//     __decorate([y(cc.Label)], t.prototype, "count", void 0);
//     __decorate([y()], t.prototype, "addtype", void 0);
//     return __decorate([_], t);
// })($resKeeper.default);
// exports.default = v;

// import {BundleNames} from "./BundleConfig";
// import {EventMgrInstance} from "./EventManager";
// import ResKeeper from "./ResKeeper";
// import UIManager from "./UIManager";
// import CommonUtils from "./CommonUtils";
// import { EVENT_TYPE } from "./EvenType";
// import {PlayerDataMgr} from "./PlayerDataManager";
// import { UIView_Home } from "./UIConfig_Home";


// const { ccclass, property, inspector } = cc._decorator;

// /**
//  * 建议类名: GoldManager
//  */
// @ccclass
// class UIHomeAddCoin extends ResKeeper {
//     @property(cc.Node)
//     icontag: cc.Node | null = null;

//     @property(cc.Label)
//     count: cc.Label | null = null;

//     @property()
//     addtype: number = 1;

//     clickthen: number = 0;

//     /**
//      * 当组件启用时调用
//      * 建议方法名: handleEnable
//      */
//     onEnable(): void {
//         EventMgrInstance.addEventListener(EVENT_TYPE.Home_Add_Gold, this.onAddGold, this);
//         EventMgrInstance.addEventListener(EVENT_TYPE.Hall_ResetRich, this.updateUi, this);
//         this.updateUi();
//     }

//     /**
//      * 更新UI显示
//      * 建议方法名: refreshUI
//      */
//     updateUi(): void {
//         if (this.count) {
//             switch (this.addtype) {
//                 case 1:
//                     this.count.string = `${PlayerDataMgr.globalData.power}/${PlayerDataMgr.globalData.maxPower}`;
//                     break;
//                 case 2:
//                     this.count.string = `${PlayerDataMgr.globalData.gold}`;
//                     break;
//                 case 3:
//                     this.count.string = `${PlayerDataMgr.globalData.diamond}`;
//                     break;
//             }
//         }
//     }

//     /**
//      * 处理添加金币事件
//      * @param e 事件类型
//      * @param t 参数
//      * 建议方法名: handleAddGold
//      */
//     onAddGold(e: number, t: any): void {
//         if (this.addtype === e) {
//             const worldPos = this.icontag?.convertToWorldSpaceAR(cc.v2(0, 0));
//             switch (e) {
//                 case 1:
//                     CommonUtils.showCoin(worldPos, null, t, "power");
//                     break;
//                 case 2:
//                     CommonUtils.showCoin(worldPos, null, t, "jinbi");
//                     break;
//                 case 3:
//                     CommonUtils.showCoin(worldPos, null, t, "zuanshi");
//                     break;
//             }
//         }
//     }

//     /**
//      * 当组件禁用时调用
//      * 建议方法名: handleDisable
//      */
//     onDisable(): void {
//         EventMgrInstance.rmEventListener(EVENT_TYPE.Home_Add_Gold, this.onAddGold, this);
//         EventMgrInstance.rmEventListener(EVENT_TYPE.Hall_ResetRich, this.updateUi, this);
//     }

//     /**
//      * 显示调试信息
//      * 建议方法名: displayDebugInfo
//      */
//     showDeBug(): void {
//         if (PlayerDataMgr.WHITE_NAME_NO_VIDEO) {
//             this.clickthen += 1;
//             console.log("点击次数", this.clickthen);
//             if (this.clickthen > 5) {
//                 UIManager.open(BundleNames.Home, UIView_Home.UI_DeBug);
//             }
//             this.unschedule(this.resetClickThen);
//             this.scheduleOnce(this.resetClickThen, 0.4);
//         }
//     }

//     /**
//      * 重置点击次数
//      * 建议方法名: resetClickCount
//      */
//     resetClickThen(): void {
//         this.clickthen = 0;
//     }
// }

// export default UIHomeAddCoin;

import { BundleNames } from "./BundleConfig";
import { EventMgrInstance } from "./EventManager";
import ResKeeper from "./ResKeeper";
import UIManager from "./UIManager";
import CommonUtils from "./CommonUtils";
import { EVENT_TYPE } from "./EvenType";
import { PlayerDataMgr } from "./PlayerDataManager";
import { UIView_Home } from "./UIConfig_Home";

const { ccclass, property, inspector } = cc._decorator;

/**
 * 建议类名: GoldManager 
 */
@ccclass
class UIHomeAddCoin extends ResKeeper {
    @property(cc.Node)
    icontag: cc.Node | null = null;

    @property(cc.Label)
    count: cc.Label | null = null;

    @property()
    addtype: number = 1;
    
    clickCount: number = 0;

    /**
     * 当组件启用时调用
     * 建议方法名: handleEnable 
     */
    onEnable(): void {
        EventMgrInstance.addListener(EVENT_TYPE.Home_Add_Gold, this.handleAddGold, this);
        EventMgrInstance.addListener(EVENT_TYPE.Hall_ResetRich, this.refreshUI, this);
        this.refreshUI();
    }

    /**
     * 更新UI显示
     * 建议方法名: refreshUI 
     */
    refreshUI(): void {
        if (this.count) {
            switch (this.addtype) {
                case 1:
                    this.count.string = `${PlayerDataMgr.globalData.power}/${PlayerDataMgr.globalData.maxPower}`;
                    break;
                case 2:
                    this.count.string = `${PlayerDataMgr.globalData.gold}`;
                    break;
                case 3:
                    this.count.string = `${PlayerDataMgr.globalData.diamond}`;
                    break;
            }
        }
    }

    /**
     * 处理添加金币事件
     * @param eventType 事件类型
     * @param params 参数
     * 建议方法名: handleAddGold 
     */
    handleAddGold(eventType: number, params: any): void {
        if (this.addtype === eventType) {
            const worldPos = this.icontag?.convertToWorldSpaceAR(cc.v2(0, 0));
            const coinType = this.getCoinType(eventType);
            if (coinType && worldPos) {
                CommonUtils.showCoinAnimation(worldPos, null, params, coinType);
            }
        }
    }

    /**
     * 获取金币类型
     * @param eventType 事件类型
     * @returns 金币类型字符串
     * 建议方法名: getCoinType 
     */
    private getCoinType(eventType: number): string | null {
        switch (eventType) {
            case 1:
                return "power";
            case 2:
                return "jinbi";
            case 3:
                return "zuanshi";
            default:
                return null;
        }
    }

    /**
     * 当组件禁用时调用
     * 建议方法名: handleDisable 
     */
    onDisable(): void {
        EventMgrInstance.removeListener(EVENT_TYPE.Home_Add_Gold, this.handleAddGold, this);
        EventMgrInstance.removeListener(EVENT_TYPE.Hall_ResetRich, this.refreshUI, this);
    }

    /**
     * 显示调试信息
     * 建议方法名: displayDebugInfo 
     */
    showDeBug(): void {
        if (PlayerDataMgr.OPEN_GM && cc.sys.isBrowser) {
            this.clickCount += 1;
            console.log("点击次数", this.clickCount);
            if (this.clickCount > 5) {
                UIManager.open(BundleNames.Home, UIView_Home.UI_DeBug);
            }
            this.unschedule(this.resetClickCount);
            this.scheduleOnce(this.resetClickCount, 0.4);
        }
    }

    /**
     * 重置点击次数
     * 建议方法名: resetClickCount 
     */
    resetClickCount(): void {
        this.clickCount = 0;
    }
}

export default UIHomeAddCoin;